package com.tx.server.message;

import com.tx.server.dto.OrderDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Component;

/**
 * stream-rabbit消息接收端
 */
@Component
// 1.绑定定义的消息接口
@EnableBinding(value = {StreamClient.class,StreamRespond.class})
public class StreamReceiver {

    Logger logger = LoggerFactory.getLogger(StreamReceiver.class);

    // 2.监听队列
//    @StreamListener(StreamClient.STREAMINPUT)
//    public void process(String message){
//        logger.info("StreamReceiver:{}", message);
//    }

    /**
     * 接收orderDTO对象 消息
     * @param message
     */
    @StreamListener(StreamClient.STREAMINPUT)
    // 消息响应
    @SendTo(StreamRespond.RESPONDINPUT)
    public String process(OrderDTO message){
        logger.info("StreamReceiver:{}", message);
        // 发送mq响应消息
        return "received";
    }

    /**
     * 接收orderDTO对象响应 消息
     * @param message
     */
    @StreamListener(StreamRespond.RESPONDINPUT)
    public void respondProcess(String message){
        logger.info("StreamReceiver:{}", message);
    }

}
